package newcoder_exp.justPractise;
import org.junit.Test;

import linked.*;
public class Ex133 {
    public class Solution {
        public ListNode oddEvenList (ListNode head) {
            if (head == null || head.next == null) return head;
            ListNode res1 = new ListNode(0), res2 = new ListNode(0), cur = head;
            res1.next = head;
            res2.next = head.next;
            ListNode temp = new ListNode(0);
            temp = res2;
            while (cur != null && cur.next != null) {
                res1.next = cur;
                res2.next = cur.next;
                cur.next = cur.next.next;
                cur = cur.next;
                res1 = res1.next;
                res2 = res2.next;
            }
            if (cur != null) {
                res1.next = cur;
                res2.next = null;
                res1 = res1.next;
            }
            res1.next = temp.next;
            return head;
        }
    }

    @Test
    public void test() {
        ListNode head = ListNode.newListNodeFromArray(new int[]{1,4,6,3,7});
        Solution s = new Solution();
        head = s.oddEvenList(head);
        System.out.println(head);
    }

}
